package BSOD;

import DataAccess.*;

/** 
 BsodManager ��ժҪ˵����
*/
public class BsodManager
{

	public BsodManager()
	{

	}

	public final boolean MoneyJudgeAndSet(int hy_num, String hy_name, java.math.BigDecimal TotalMoney, String zhushu)
	{
		Bank bk = new Bank();

		if (!bk.SelectByPk(hy_num))
		{
			return false;
		}
		if (!bk.getzt().equals("q"))
		{
			return false;
		}
		if (bk.getBalance().compareTo(TotalMoney) < 0)
		{
			return false;
		}
		bk.setBalance(bk.getBalance().subtract(TotalMoney));
		bk.setOutput_Money(bk.getOutput_Money().add(TotalMoney));
	//	bk.BeginTransaction();
		if (!bk.Update())
		{
	//		bk.Rollback();
			return false;
		}

		 Bank_Log log = new Bank_Log();
		log.ReferenceTransactionFrom(bk);
		log.setHy_Num(hy_num);
		log.sethy_name(hy_name);
		log.setBalance(TotalMoney.negate());
		log.setbz("����" + zhushu + "ע");
		log.setAddtime(java.time.LocalDateTime.now());
		if (!log.Insert())
		{
	//		log.Rollback();
			return false;
		}
	//	log.Commit();
		return true;
	}


	public final boolean HadMoneyJudgeAndSet(int hy_num, String hy_name, java.math.BigDecimal TotalMoney, String zhushu)
	{
		Bank bk = new Bank();

		if (!bk.SelectByPk(hy_num))
		{
			return false;
		}
		if (!bk.getzt().equals("q"))
		{
			return false;
		}
		if (bk.getBalance().compareTo(TotalMoney) < 0)
		{
			return false;
		}
		return true;

	}


}